#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=500000;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

int s(int n) {
  return n*(n+1)/2;
}

class SegmentTree {
public:
  int a[4*maxn+1], b[4*maxn+1], c[4*maxn+1];

  void init(int o, int l, int r, int u, int v) {
    a[o] = l-v, b[o] = r-u, c[o]=(-l-l*l-r*r+r)/2+u*v-u+v;
    if (l!=r) {
      int mid=(l+r)/2;
      init(o*2, l, mid, l, r);
      init(o*2+1, mid+1, r, l, r);
      a[o] += a[o*2]+a[o*2+1], b[o] += b[o*2]+b[o*2+1], c[o] += c[o*2]+c[o*2+1];
    }
  }

  int solve(int o, int l, int r, int x, int y) {
    int ret=0;
    if (x<=l && y>=r) {
      int d=0, e=0, f=0;
      if (l!=r) {
	d = a[o*2]+a[o*2+1], e = b[o*2]+b[o*2+1], f = c[o*2]+c[o*2+1];
      }
      ret += x*d+y*e+f+s(y-x+1)-s(l-x)-s(y-r);
    } else {
      if (x>=l && y<=r) {
	ret += s(y-x+1);
      } else {
	if (x>l) {
	  ret += s(y-x+1)-s(x-l);
	} else {
	  ret += s(y-x+1)-s(r-y);
	}
      }
      if (l!=r) {
	int mid=(l+r)/2;
	if (x<=mid && y>=l) {
	  ret += solve(o*2, l, mid, x, y);
	}
	if (x<=r && y>mid) {
	  ret += solve(o*2+1, mid+1, r, x, y);
	}
      }
    }
    return ret;
  }
};

int main() {
  freopen("ran.in", "r", stdin);
  freopen("ran.out", "w", stdout);

  static SegmentTree sgt;
  int n, q, opt;
  scanf("%d %d %d", &n, &q, &opt);
  sgt.init(1, 1, n, 0, 0);
  int lastans = 0;
  for (int i=1; i<=q; i++) {
    int l, r, a, b;
    scanf("%d %d", &l, &r);
    a = (l^(lastans*opt))%n+1, b=(r^(lastans*opt))%n+1;
    l = min(a, b), r = max(a, b);
    lastans = sgt.solve(1, 1, n, l, r);
    printf("%d\n", lastans);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
